package org.dbstar.scheduler.beans;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * 用户实体类
 * 
 * @author 代波
 * @since 1.0.0
 * @version 1.0.0
 * @date 2012-6-6
 */
public class User implements Serializable, Cloneable, Comparable<User> {
	private static final long serialVersionUID = -2872795814304985933L;

	private String username;
	private String displayName;
	private Set<String> authorities = new HashSet<String>();

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public Set<String> getAuthorities() {
		return authorities;
	}

	public void addAuthority(String authority) {
		authorities.add(authority);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((username == null) ? 0 : username.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}

	@Override
	public int compareTo(User o) {
		return username.compareTo(o.username);
	}

	@Override
	public User clone() throws CloneNotSupportedException {
		User user = (User) super.clone();
		user.authorities = new HashSet<String>(authorities);
		return user;
	}
}
